﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Globalization
Imports System.Web.Configuration

Public Class MyObj
    Public Shared Function GetCodeMappingData(ByVal tableName As String, ByVal columnName As String) As DataTable
        Return GetCodeMappingData(tableName, columnName, False)
    End Function

    Public Shared Function GetCodeMappingData(ByVal tableName As String, ByVal columnName As String, ByVal listAll As Boolean) As DataTable
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select cm.* ")
        sql.AppendFormat("from CodeMapping cm ")
        sql.AppendFormat("where cm.TableName = '{0}' ", tableName)
        sql.AppendFormat("and cm.ColumnName = '{0}' ", columnName)

        If listAll = False Then
            sql.AppendFormat("and Active = 'Y' ")
        End If

        sql.AppendFormat("order by cm.Sequence ")

        Return dat.GetData(sql.ToString(), Nothing, CommandType.Text, "dt").Tables(0)
    End Function

    Public Shared Function GetCodeMappingData(ByVal tableName As String, ByVal columnName As String, ByVal columnExpression As String) As DataTable
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select cm.*, {0} ", columnExpression)
        sql.AppendFormat("from CodeMapping cm ")
        sql.AppendFormat("where cm.TableName = '{0}' ", tableName)
        sql.AppendFormat("and cm.ColumnName = '{0}' ", columnName)
        sql.AppendFormat("and Active = 'Y' ")
        sql.AppendFormat("order by cm.Sequence ")

        Return dat.GetData(sql.ToString(), Nothing, CommandType.Text, "dt").Tables(0)
    End Function

    Public Shared Function GetTownData() As DataTable
        Return GetTownData("TPC")
    End Function

    ''' <summary>
    ''' 取得鄉鎮資料
    ''' </summary>
    ''' <param name="countyID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetTownData(ByVal countyID As String) As DataTable
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select r.RegionName,r.RegionID ")
        sql.AppendFormat("from Region r ")
        sql.AppendFormat("where r.Parent = '{0}' ", countyID)
        sql.AppendFormat("order by r.RegionName ") 'Mod by Shihyu 2010/10/12

        Return dat.GetData(sql.ToString(), Nothing, CommandType.Text, "dt").Tables(0)
    End Function

    ''' <summary>
    ''' 取得村里資料
    ''' </summary>
    ''' <param name="townID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetVillageData(ByVal townID As String) As DataTable
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select r.RegionID, r.RegionName ")
        sql.AppendFormat("from Region r ")
        sql.AppendFormat("where r.Parent = '{0}' ", townID)
        sql.AppendFormat("order by r.RegionName ") 'Mod by Shihyu 2010/10/12

        Return dat.GetData(sql.ToString(), Nothing, CommandType.Text, "dt").Tables(0)
    End Function

    ''' <summary>
    ''' 依登入者權限列出所有組織
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetDDLOrganizationData() As DataTable
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.Length = 0
        sql.AppendFormat("select ua.*, o.OrganizationName, UOrganizationID ")
        sql.AppendFormat("from UserOrganizationAuth ua ")
        sql.AppendFormat("inner join OrganizationView o on ua.OrganizationID = o.OrganizationID and ua.VOrganizationID = o.VOrganizationID ")
        sql.AppendFormat("where ua.UserID = '{0}' ", clsAuth.GetUserID())
        sql.AppendFormat("and o.VOrganizationID = -1 ")
        sql.AppendFormat("order by o.VOrganizationCode, o.OrganizationCode ")

        dt = dat.GetData(sql)

        Return dat.GetData(sql)
    End Function

    Public Shared Function GetAllDDLOrganizationData() As DataTable
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.Length = 0
        sql.AppendFormat("select o.OrganizationName, UOrganizationID ")
        sql.AppendFormat("from OrganizationView o ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat("and o.VOrganizationID = -1 ")
        sql.AppendFormat("and o.Active = 'Y' ")
        sql.AppendFormat("order by o.VOrganizationCode, o.OrganizationCode ")

        dt = dat.GetData(sql)

        Return dat.GetData(sql)
    End Function

    Public Shared Function GetDDLVOrganizationData() As DataTable
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.Length = 0
        sql.AppendFormat("select ua.VOrganizationID, o.VOrganizationName ")
        sql.AppendFormat("from UserOrganizationAuth ua ")
        sql.AppendFormat("inner join VOrganizationViewV2 o on  ua.VOrganizationID = o.VOrganizationID  ")
        sql.AppendFormat("where ua.UserID = '{0}' ", clsAuth.GetUserID())
        sql.AppendFormat("order by o.VOrganizationName ")  'Add By Angus 2010/05/18
        'sql.AppendFormat("order by o.VOrganizationCode, o.OrganizationCode ")

        dt = dat.GetData(sql)

        Return dat.GetData(sql)
    End Function

    ''' <summary>
    ''' 列出所有運用單位
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetDDLDirectOrganizationData() As DataTable
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.Length = 0
        sql.AppendFormat("select o.OrganizationName, UOrganizationID ")
        sql.AppendFormat("from OrganizationView o ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat("and o.OrganizationType in ('O','P') ")
        sql.AppendFormat("and o.Active = 'Y' ")
        sql.AppendFormat("order by o.OrganizationName ") ' Mod By Shihyu 2010/10/25
        'sql.AppendFormat("order by o.VOrganizationCode, o.OrganizationCode ") 

        dt = dat.GetData(sql)

        Return dat.GetData(sql)
    End Function

    ''' <summary>
    ''' 列出所有運用單位(志工統計報表專用)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetDDLReportOrganizationData() As DataTable
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.Length = 0
        sql.AppendFormat("select o.OrganizationName, UOrganizationID ")
        sql.AppendFormat("from OrganizationView o ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat("and o.OrganizationType in ('O','P') ")
        sql.AppendFormat("and o.Active = 'Y' ")
        sql.AppendFormat("and Parent is not null and (Len(OrganizationCode)=4 or Len(VOrganizationCode)=4) ")
        sql.AppendFormat("order by o.OrganizationName ") ' Mod By Shihyu 2010/10/25
        'sql.AppendFormat("order by o.VOrganizationCode, o.OrganizationCode ")

        dt = dat.GetData(sql)

        Return dat.GetData(sql)
    End Function
    Public Shared Function GetOrganizationData(ByVal IsVolunteerLeader As Boolean) As DataTable
        Dim dt As Data.DataTable
        Dim dat As New clsData
        If IsVolunteerLeader = True Then
            Dim sql As New MyStringBuilder
            sql.AppendFormat("select distinct ov.OrganizationName, o.DirectUOrganizationID as UOrganizationID from VOrganizationViewV2 o ")
            sql.AppendFormat("inner join OrganizationView ov on o.DirectUOrganizationID=ov.UOrganizationID ")
            sql.AppendFormat("inner join OtherOrganizationMapping om on '-1,'+cast(o.VOrganizationID as nvarchar(50))=om.UOrganizationID ")
            sql.AppendFormat("where om.UserID = '{0}' ", clsAuth.GetUserID())
            sql.AppendFormat("order by ov.OrganizationName ")
            dt = dat.GetData(sql)
        Else
            Dim sql As New MyOrganizationDataFilter

            'sql.AppendFormat("select o.OrganizationName,o.UOrganizationID from OrganizationView o ")
            'sql.AppendFormat("where OrganizationType <> 'V' and Active='Y' ")
            'sql.AppendFormat("order by OrganizationName ")
            sql.AppendFormat("    select OrganizationName,UOrganizationID from OrganizationView   ")
            sql.AppendFormat("    where OrganizationType='O'   and Active='Y' ")
            sql.AppendFormat("    union ")
            sql.AppendFormat("    select OrganizationName,UOrganizationID from OrganizationView   ")
            sql.AppendFormat("    where OrganizationType='P'   and Active='Y' ")
            sql.AppendFormat("order by OrganizationName ")
            dt = dat.GetData(sql)
        End If

        Return dt
    End Function
    Public Shared Function GetAllOrganizationData() As DataTable
        Dim dt As Data.DataTable
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Sql.AppendFormat("select o.OrganizationName,o.UOrganizationID from OrganizationView o ")
        Sql.AppendFormat("where OrganizationType <> 'V' and Active='Y' ")
        Sql.AppendFormat("order by OrganizationName ") 'Add by Shihyu 2010/10/12

        dt = dat.GetData(sql)
        Return dt
    End Function
    Public Shared Function GetVOrganizationData(ByVal OrganizationID As String) As DataTable

        Dim sql As New MyOrganizationDataFilter
        Dim dat As New clsData

        sql.AppendFormat("select VOrganizationName,VOrganizationID,'-1'+','+cast(VOrganizationID as nvarchar)  as UOrganizationID from VOrganizationViewV2  ")
        sql.AppendFormat("where DirectUOrganizationID = '{0}' ", OrganizationID)
        sql.AppendFormat("order by VOrganizationName ") 'Add by Shihyu 2010/10/12
        '   MyObj.WriteLog(sql.ToString())
        Return dat.GetData(sql)

    End Function
    ''' <summary>
    ''' 取得參數
    ''' </summary>
    ''' <param name="parameterType"></param>
    ''' <param name="parameterName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetParameter(ByVal parameterType As String, ByVal parameterName As String) As String
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select ParameterValue ")
        sql.AppendFormat("from SystemParameter p ")
        sql.AppendFormat("where ParameterType = '{0}' ", parameterType)
        sql.AppendFormat("and ParameterName = '{0}' ", parameterName)

        Return dat.GetData(sql).Rows(0)(0).ToString()
    End Function

    Public Shared Function GetDDLSelectAllItem() As ListItem
        Dim li As New ListItem

        li.Text = "----全部----"
        li.Value = ""

        Return li
    End Function

    Public Shared Function GetDDLPleaseChooseItem() As ListItem
        Dim li As New ListItem

        li.Text = "----請選擇----"
        li.Value = ""

        Return li
    End Function

    Public Shared Sub ShowMessage(ByVal message As String)
        Dim js As String

        js = String.Format("alert('{0}');", message)
        ScriptManager.RegisterClientScriptBlock(TryCast(HttpContext.Current.Handler, Page), GetType(String), message.ToString, js, True)
    End Sub

    Public Shared Sub ShowMessage(ByVal format As String, ByVal ParamArray args() As Object)
        MyObj.ShowMessage(String.Format(format, args))
    End Sub

    Public Shared Sub WriteLog(ByVal message As MyStringBuilder)
        MyObj.WriteLog(message.ToString())
    End Sub

    Public Shared Sub WriteLog(ByVal message As String)
        Dim fileName As String = HttpContext.Current.Server.MapPath(String.Format("~\log\{0:yyyyMMdd}.txt", DateTime.Now))
        Dim sr As New IO.StreamWriter(fileName, True)

        sr.WriteLine(message)

        sr.Close()
    End Sub

    Public Shared Sub WriteErrorLog(ByVal message As MyStringBuilder)
        MyObj.WriteErrorLog(message.ToString())
    End Sub

    Public Shared Sub WriteErrorLog(ByVal message As String)
        Dim fileName As String = HttpContext.Current.Server.MapPath(String.Format("~\log\{0:yyyyMMdd}_ErrorLog.txt", DateTime.Now))
        Dim sr As New IO.StreamWriter(fileName, True)

        sr.WriteLine(message)

        sr.Close()
    End Sub

    Public Shared Sub MatchItem(ByVal Item As IListControl, ByVal Value As String)
        Item.Text = Value
    End Sub

    Public Shared Sub MatchItem(ByVal Item As DropDownList, ByVal Value As String)
        Item.SelectedIndex = Item.Items.IndexOf(Item.Items.FindByValue(Value.Trim()))
    End Sub

    Public Shared Sub MatchItem(ByVal Item As RadioButtonList, ByVal Value As String)
        Item.SelectedIndex = Item.Items.IndexOf(Item.Items.FindByValue(Value.Trim()))
    End Sub

    ''' <summary>
    ''' 取得新增完畢之 row id
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Function GetIdentity() As Integer
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select @@identity ")

        Return dat.GetData(sql.ToString(), Nothing, CommandType.Text, "dt").Tables(0).Rows(0)(0)
    End Function

    ''' <summary>
    ''' 匯出 Excel時使用
    ''' </summary>
    ''' <param name="gv"></param>
    ''' <param name="dataField"></param>
    ''' <param name="headerText"></param>
    ''' <remarks></remarks>
    Public Shared Sub AddBoundField(ByVal gv As GridView, ByVal dataField As String, ByVal headerText As String)
        Dim field As New BoundField
        field.DataField = dataField
        field.HeaderText = headerText
        gv.Columns.Add(field)
    End Sub

    Public Shared Sub ExportToExcel(ByVal gv As GridView, ByVal fileName As String)
        Dim tw As System.IO.StringWriter = New System.IO.StringWriter
        Dim hw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(tw)
        Dim response As HttpResponse = HttpContext.Current.Response

        gv.AutoGenerateColumns = False

        'hw.WriteLine("<form runat=server>");        	

        response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName)
        response.ContentType = "application/vnd.ms-excel"
        response.Charset = "utf-8"
        gv.Page.ResponseEncoding = "utf-8"

        'Add UTF-8 BOM
        response.BinaryWrite(New Byte() {&HEF, &HBB, &HBF})

        gv.RenderControl(hw)

        '//this.EnableViewState = false;
        response.Write("<META name=generator CONTENT= 帳號:" + clsAuth.GetUserID() & ",下載時間:" + Today.Year.ToString() & "-" & Today.Month.ToString() & "-" & Today.Day.ToString() & Space(1) & Now.Hour.ToString() & ":" & Now.Minute.ToString() & ":" & Now.Second.ToString() & ",IP:" + MyObj.getIP() & ">")
        response.Write(tw.ToString())
        response.End()
    End Sub

    ''' <summary>
    ''' 取得登入者所屬單位下的社區發展協會志工隊
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetPOrganization() As DataTable
        Dim sql As New MyOrganizationDataFilter
        Dim dat As New clsData

        sql.AppendFormat("select * ")
        sql.AppendFormat("from GetPOrganizationTree('{0}') ", clsAuth.GetUser().UOrganizationID)

        Return dat.GetData(sql)
    End Function

    ''' <summary>
    ''' 取得登入者所屬單位下的志工隊
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetVOrganization() As DataTable
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select v.VOrganizationName as OrganizationName, v.VOrganizationID, v.UOrganizationID ")
        sql.AppendFormat("from VOrganizationView v ")
        sql.AppendFormat("order by OrganizationName ")  'Add By Angus 2010/05/18

        Return dat.GetData(sql)
    End Function

    Public Shared Function GetFilePath(ByVal fileGroupID As String, Optional ByVal IncludeFileFormat As Boolean = False) As String
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select fg.* from FileGroup fg ")
        sql.AppendFormat("where FileGroupID = '{0}' ", fileGroupID)

        Dim dt As Data.DataTable = dat.GetData(sql)

        If IncludeFileFormat = True Then
            Return dt.Rows(0)("FilePath") + dt.Rows(0)("FileFormat")
        Else
            Return dt.Rows(0)("FilePath")
        End If
    End Function

    Public Shared Sub SetDateLocale()
        SetDateLocale("")
    End Sub

    Public Shared Sub SetDateLocale(ByVal region As String)
        Select Case region
            Case "zh-TW"
                Dim culture As New CultureInfo("zh-TW")

                culture.DateTimeFormat.Calendar = New TaiwanCalendar()
                'culture.DateTimeFormat.ShortDatePattern = "民國yyyy年MM月dd日"
                culture.DateTimeFormat.ShortDatePattern = "yyyy.MM.dd"
                culture.DateTimeFormat.ShortTimePattern = ""
                culture.DateTimeFormat.LongTimePattern = ""

                System.Threading.Thread.CurrentThread.CurrentCulture = culture
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture
            Case ""
                Dim culture As New CultureInfo("zh-TW")

                System.Threading.Thread.CurrentThread.CurrentCulture = culture
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture
        End Select
    End Sub

    Public Shared Function IsProductionEnvironment() As Boolean
        Dim buildType As String = MyObj.GetParameter("Environment", "Build")
        'WebConfigurationManager.AppSettings("Environment")

        If buildType.ToLower() = "production" Then
            Return True
        Else
            Return False
        End If
    End Function

    'Public Shared Function GetUploadFileVirtualPath(ByVal fileID As String) As String
    Public Shared Function GetUploadPath(ByVal recordType As String, ByVal recordID As String) As String
        Return GetUploadPath(recordType, recordID, True)
    End Function

    Public Shared Function GetUploadPath(ByVal recordType As String, ByVal recordID As String, ByVal virtual As Boolean) As String
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select uf.* from UploadFiles uf ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat("and theClass = '{0}' ", recordType)
        sql.AppendFormat("and theType = '{0}' ", recordID)

        'sql.AppendFormat("where FileSaveName = '{0}' ", uploadID)

        Dim dt As Data.DataTable = dat.GetData(sql)

        If dt.Rows.Count = 0 Then
            Return ""
        End If

        If virtual = True Then
            Return dt.Rows(0)("FileSavePath") + dt.Rows(0)("FileSaveName").ToString() + "." + dt.Rows(0)("FileType")
        Else
            Return HttpContext.Current.Server.MapPath(dt.Rows(0)("FileSavePath")) + dt.Rows(0)("FileSaveName").ToString() + "." + dt.Rows(0)("FileType")
        End If


    End Function

    Public Shared Function GetCreateBySQL() As MyStringBuilder
        Dim sql As New MyStringBuilder

        sql.AppendFormat(", getdate() ")
        sql.AppendFormat(", @CreateBy ")

        sql.AddWithValue("CreateBy", clsAuth.GetUserID())

        Return sql
    End Function

    Public Shared Function GetUpdateBySQL() As MyStringBuilder
        Dim sql As New MyStringBuilder

        sql.AppendFormat(", UpdateDate = getdate() ")
        sql.AppendFormat(", UpdateBy = @UpdateBy ")

        sql.AddWithValue("UpdateBy", clsAuth.GetUserID())

        Return sql
    End Function

    Public Shared Function IsDBNull(ByVal s As Object, ByVal nullIf As String) As String
        If s Is DBNull.Value Then
            Return nullIf
        Else
            Return s
        End If
    End Function
    Public Shared Function IsSystem(ByVal UserID As String) As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.Length = 0
        sql.AppendFormat("Select RoleID from RoleUserMapping ")
        sql.AppendFormat("where UserID = '{0}' ", UserID)
        sql.AppendFormat("and RoleID in (3,4) ")


        If dat.GetData(sql).Rows.Count <= 0 Then
            Return False
        Else
            Return True
        End If
    End Function
    Public Shared Function getIP() As String
        Dim strIPAddr As String
        'Dim ip As String
        If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Or InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
            strIPAddr = Request.ServerVariables("REMOTE_ADDR")
        ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
            strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") - 1)
        ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
            strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") - 1)
        Else
            strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
        End If

        Return Mid(strIPAddr, 1, 30).Trim.ToString()
    End Function

    '個資是否清查完畢
    Public Shared Function VolunteerBasicDataIsCheck(ByVal VOrganizationID As String) As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData
        Dim dt As Data.DataTable
        sql.AppendFormat("Select Locked From Vorganization ")
        sql.AppendFormat("Where VOrganizationID ='{0}' ", VOrganizationID)
        dt = dat.GetData(sql)
        '  MyObj.WriteLog(sql.ToString())
        If dt.Rows.Count > 0 Then
            If dt.Rows(0)("Locked").ToString() = "Y" Then
                Return True
            Else
                Return False
            End If
        End If
    End Function
    Public Shared Sub ChangeRecord(ByVal VolunteerID As String, ByVal VOrganizationID As String, ByVal ChangeType As String, ByVal ChangeReason As String)
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("Insert Into ChangeRecord (ChangeID,VOrganizationID,ChangeType,ChangeReason,CreateDate,CreateBy) ")
        sql.AppendFormat("Select '{0}' ", VolunteerID)
        sql.AppendFormat(",'{0}' ", VOrganizationID)
        sql.AppendFormat(",'{0}' ", ChangeType)
        sql.AppendFormat(",'{0}' ", ChangeReason)
        sql.AppendFormat(",getdate() ")
        sql.AppendFormat(",'{0}' ", clsAuth.GetUserID())


        dat.AccData(sql)
    End Sub
    '管理員,公所人員及志工隊長
    Public Shared Function IsOrgAdmin(ByVal UserID As String) As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.Length = 0
        sql.AppendFormat("select UserName from AdminVorganizationView ")
        sql.AppendFormat("where UserID = '{0}' ", UserID)
        sql.AppendFormat("and Active='Y' ")



        If dat.GetData(sql).Rows.Count <= 0 Then
            Return False
        Else
            Return True
        End If
    End Function
    Public Shared Function GetGroup(ByVal VOrganizationID As Integer) As Data.DataTable
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.Length = 0

        sql.AppendFormat("SELECT distinct gvm.GroupID,gvm.GroupName,vo.VOrganizationName FROM GroupVOrganizationMapping gvm ")
        sql.AppendFormat("INNER JOIN VOrganizationViewV2 vo on gvm.VOrganizationID=vo.VOrganizationID ")
        sql.AppendFormat("WHERE gvm.VOrganizationID = {0} ", VOrganizationID)

        Return dat.GetData(sql)
    End Function
End Class

